<script>
import {mapActions, mapState, mapMutations} from 'vuex'

export default {

  computed:{
    ...mapState('http', ['token'])
  },
  
  methods: {
    ...mapActions('http', ['getWXUserInfo', 'login', 'localUserInfo']),
    ...mapMutations('http', ['setinitStatus']),

    async init(count=0, time){

        wx.showLoading({
          title: '加载中',
        });
     
        let userInfo = this.getWXUserInfo();
        userInfo.then(status =>{})
        let loginStatus = await this.login();
        
        //请求用户数据
        await this.localUserInfo()
        

        wx.hideLoading();
        loginStatus||wx.showModal({
          'title': '加载失败',
        })

      // 标记初始状态
      this.setinitStatus(true)
    }

  },

  async onLaunch () {
    
    await this.init();
    
    // 调用API从本地缓存中获取数据
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

  }
}
</script>

<style lang='less'>
.container {
  height: 100%;
  box-sizing: border-box;
  font-size: 32rpx;
  background: #efefef;
}
/* this rule will be remove */
* {
  transition: width 2s;
  -moz-transition: width 2s;
  -webkit-transition: width 2s;
  -o-transition: width 2s;
}
</style>
